package net.alpenviewer.app;
import java.io.File;

import net.alpenviewer.map.SRTM;
import net.alpenviewer.map.SRTMPreprocessor;

/** */
public class PreprocessSRTM {

	private static final File srcDir          = new File("srtm_src");
	private static final File preprocessedDir = new File("srtm");

	static {
		if (!srcDir.exists() || !srcDir.isDirectory()) {
			throw new IllegalArgumentException(srcDir.getName() + " does not exist or it is not a directory");
		}
		if (!preprocessedDir.exists()) {
			preprocessedDir.mkdir();
		} else if (!preprocessedDir.isDirectory()) {
			throw new IllegalArgumentException(preprocessedDir.getName() + " is not a directory");
		}
	}

	public static void main(String[] args) throws Exception {

		long t = System.currentTimeMillis();

		SRTMPreprocessor prep = new SRTMPreprocessor();
		
		final File[] files = srcDir.listFiles();
		for (File file : files) {
			if (file.isFile() && file.getName().toLowerCase().endsWith(".hgt")) {					
				final SRTM srtm = new SRTM(file);
				prep.preprocess(srtm, preprocessedDir);
			}			
		}		

		t = System.currentTimeMillis() - t;		
		System.out.println("processing elapsed " + t + " millis.");
	}

}
